package Text2;

import java.util.*;

public class Main {
    static final int N = 10010;
    static int[] q = new int[N];

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            q[i] = scanner.nextInt();
        }
        int res=0;
        for (int l = 0; l < n; l++) {
            int max=Integer.MIN_VALUE;
            int min=Integer.MAX_VALUE;
            for (int r = l; r <n ; r++) {
                max=Math.max(max,q[r]);
                min=Math.min(min,q[r]);
                if(r-l==max-min){
                  res++;
                }
            }
        }
        System.out.println(res);
    }
}
